package com.example.rule.rule;

import com.example.rule.core.Action;
import com.example.rule.core.Condition;
import com.example.rule.core.Facts;

import java.math.BigDecimal;

/**
 * @author Jason - Chusifeng
 * @version 1.0.0
 * @ClassName SpELRule.java
 * @PackageName com\welab\vb\payment\transaction\rule\rule\SpELRule.java
 * @Description 基于spel的rule规则实现
 * @createTime 2022年10月10日 10:41:29
 */
public class CommonRule extends BasicRule {
    private Condition condition;
    private Action action;

    public CommonRule(Condition condition, Action action) {
        super();
        this.condition = condition;
        this.action = action;
    }

    public CommonRule(String name, Condition condition, Action action) {
        super(name);
        this.condition = condition;
        this.action = action;
    }

    public CommonRule(String name, String description, Condition condition, Action action) {
        super(name, description);
        this.condition = condition;
        this.action = action;
    }

    @Override
    public boolean evaluate(Facts facts) {
       return condition.evaluate(facts);
    }

    @Override
    public BigDecimal execute(Facts facts) throws Exception {
        return action.execute(facts);
    }
}
